package com.wcl.demo.ui.activity;

import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.easemob.EMValueCallBack;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMGroupInfo;
import com.easemob.chat.EMGroupManager;
import com.easemob.exceptions.EaseMobException;
import com.wcl.demo.R;
import com.wcl.demo.ui.adapter.AddPublicGroupAdapter;
import com.wcl.demo.utils.ActivityUtils;

import java.util.List;

import butterknife.Bind;

/**
 * Created by dllo on 15/11/24.
 */
public class AddPublicGroupActivity extends BaseActivity{
    private RecyclerView recyclerView;
    private AddPublicGroupAdapter adapter;
  //  private List<EMGroupInfo> infos;
    private ImageView backGroup;

//    private Handler handler = new Handler(new Handler.Callback() {
//        @Override
//        public boolean handleMessage(Message msg) {
//            try {
//                infos = EMGroupManager.getInstance().getAllPublicGroupsFromServer();
//            } catch (EaseMobException e) {
//                e.printStackTrace();
//            }
//            return false;
//        }
//    });


    public AddPublicGroupActivity() {

        EMGroupManager.getInstance().asyncGetAllPublicGroupsFromServer(new EMValueCallBack<List<EMGroupInfo>>() {

            @Override
            public void onSuccess(List<EMGroupInfo> value) {
                // TODO Auto-generated method stub
                adapter.addData(value);
            }

            @Override
            public void onError(int error, String errorMsg) {
                // TODO Auto-generated method stub

            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_add_public_group;
    }

    @Override
    protected void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.addGroup_recyclerView);
        backGroup = (ImageView) findViewById(R.id.activity_add_publicgroup_bac_Iv);
        backGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        adapter = new AddPublicGroupAdapter();
        GridLayoutManager manager = new GridLayoutManager(this , 1);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
    }
}
